var $edit_viewstate = 'VIEW';//编辑页面状态:VIEW,EDIT,ADD
var $edit_defaultGridParam = {//默认表格设置,分录使用
	width: '99%', 
    height: '99%', 
    root:'items',
    record:'recordCount',
    enabledEdit:true,
    checkbox: false,
    rownumbers:false,
    enabledSort:false,
    usePager:false,
    enabledEdit: true,
    onBeforeShowData:function(data){
    	//用于支持多级取值方式绑定如name:'data.aa.dd.bcc'的方式
    	function updateColumnData(column){
    		var name = column.columnname;
    		if(name && name.indexOf('.')>0){
    			var names = name.split('.');
    			var fieldName = getDataFieldName(data);
    			if(data[fieldName]){
	       			 for(var i = 0; i < data[fieldName].length; i++){
	       				 var tmp = data[fieldName][i];
	       				 for(var j = 0;j < names.length; j++){
	       					 if(tmp[names[j]]){
	       						 tmp = tmp[names[j]];
	       					 }else{
	       						 tmp = null;
	       						 break;
	       					 }
	       				 }
	       				data[fieldName][i][name] = tmp;
	       			 }
    			}
    		}
    		if(column.columns && column.columns.length > 0){
    			for(var i = 0; i < column.columns.length;i++){
    				updateColumnData(column.columns[i]);
    			}
    		}
    	}
    	if(this.columns){
    		for(var i = 0; i < this.columns.length;i++){
    			updateColumnData(this.columns[i]);
    		}
    	}
    	return true;
    }
};
//查看状态下，所有的输入框全部置为disabled
$(document).ready(function(){
	var loc = self.location+"";
	var queryString = loc.replace(/^[^\?]+\??/,'');
	var params = parseQuery( queryString );
	$edit_viewstate = params['VIEWSTATE'];
	if($edit_viewstate=='VIEW'){
		//输入框
		$('input,textarea').each(function(){
			$(this).attr('disabled','disabled');
		});
		//超链接
		$('a').each(function(){
			if(!$(this).attr('escape')){//如果有escape属性，则跳过
				$(this).removeAttr('onclick');
				$(this).attr('href','javascript:void(0)');
			}
		});
		//F7
		$('div[class="f7"]').each(function(){
			$(this).find('span').each(function(){
				$(this).removeAttr('onclick');
			});
			$(this).find('strong').each(function(){
				$(this).removeAttr('onclick');
			});
		});
	}
});
function parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

$(document).ajaxError(function(event,request, settings){
	var content = '不好意思,出错啦。';
	function showErrorMsg(){
		var errorLog = art.dialog({
			title:"详细信息",
			content:'<div>'+request.responseText.substring(request.responseText.indexOf('<body>')+6,request.responseText.indexOf('</body>'))+'</div>',
			lock:true,
			height:'320px',
			width:'400px',
			button:[{name:"确定"}]
		});
		return false;
	}
	function closeErrorDialog(){
		dialog.close();
	}
	var dialog = art.dialog({
		title:"信息提示",
		icon:"error",
	    content: content,
	    id: "ajaxErrorDialog",
	    lock:true,
	    button:[{name:"详细信息",callback:showErrorMsg},{name:"确定",callback:closeErrorDialog}]
	});
	dialog.show();
});
